* ======================================
* ----------- Panel Voters ------------
* ======================================
* Creates a balanced panel of voters in 2015 and 2019 (main sample)

	use $dta\Population.dta, replace
	
	* Import turnout
	merge 1:1 idPers year using "$dta\ImportTurnout.dta", nogen ///
		keep(master matched)
	

* Restrict sample
* ===============

	* Municipalities with complete records 
	merge m:1 knr using "$dta\Turnout_knr.dta", nogen keep(master matched)
	keep if knr_inSample == 1
	drop knr_inSample

	* Drop any politicians 
	merge 1:1 year idPers using "$dta\ImportPoliticians.dta", nogen ///
	keep(master matched) keepusing(running_loc running_reg)
	drop if running_loc == 1
	drop if running_reg == 1
	
	* Missing vote
	drop if vote == . 

	* Alive, residing in sample area in both periods etc.
	bysort idPers: keep if _N == 2


* Rename variables
* ================

	rename idPers Voter_id
	rename knr Voter_knr
	rename bsu Voter_bsu
	rename age Voter_age
	rename birthyear Voter_birthyear
	rename birthcountry Voter_birthcountry
	rename immigrant Voter_immigrant
	rename female Voter_female
	rename vote Voter_turnout
	
	keep Voter_* year

	save "$dta\PanelVoters.dta", replace